﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HZ.Supervise.Model.Enum;
using HZ.Supervise.Model;
using HZ.Supervise.IBLL;

namespace HZ.Supervise.Web.Company
{
    public partial class CompanyList_PS_DZ : BasePage
    {
        HZ.Supervise.IBLL.IExecuteContext iEC = HZ.Supervise.BLLFactory.ExecuteContext();
        IBLL_User iu = BLLFactory.BLL_User();
        KeyOperationLogJG kj;
        public CompanyList_PS_DZ()
        {
            this.ModuleNo = Module.耗材配送汇总管理.ToString();
            this.PageOperateType = OperateType.配送企业列表.ToString();
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            { 
                ddlArea.InitAreaID = CurrentAccount.GetUser().Org.Area.AreaID; 
                //绑定列表数据
                //CompanyList_PS_DataBind();
            }
        }

        /// <summary>
        /// 绑定数据源方法
        /// 董辉
        /// 2011-3-29 16:26
        /// </summary>
        private void CompanyList_PS_DataBind()
        {
            int t = 0; 
            HZ.Supervise.Model.View.HospitalProcureCatalog hospro = new HZ.Supervise.Model.View.HospitalProcureCatalog(); 
            hospro.CompanyName_PS = HZ.Supervise.DAL.DAL_Helper.Replace(txtCompanyPS.Text.ToString().Trim());  
            hospro.AreaID = ddlArea.SelectedAreaID;
            System.Data.DataTable dt = iEC.GetCompanyPS_ZongList_DZ(hospro, this.AspNetPager_CompanyList_PS.CurrentPageIndex, AspNetPager_CompanyList_PS.PageSize, out t); 
            AspNetPager_CompanyList_PS.RecordCount = t; 
            gvwPSLInfo.PageSize = AspNetPager_CompanyList_PS.PageSize; 
            this.gvwPSLInfo.DataSource = dt; 
            this.gvwPSLInfo.DataBind();
            AddLog(string.Format("查询配送企业列表低值数据!(配送企业列表)"));
        }

        /// <summary>
        /// 查询数据事件 
        /// </summary>
        /// <param name="sender">事件发送源</param>
        /// <param name="e">事件参数</param>
        protected void btnQuery_Click(object sender, EventArgs e)
        {
            this.AspNetPager_CompanyList_PS.CurrentPageIndex = 1;
        }

        /// <summary>
        /// 导出数据事件 
        /// </summary>
        /// <param name="sender">事件发送源</param>
        /// <param name="e">事件参数</param>
        protected void btnExcel_Click(object sender, EventArgs e)
        {
            int t = 0;

            HZ.Supervise.Model.View.HospitalProcureCatalog hospro = new HZ.Supervise.Model.View.HospitalProcureCatalog();

            hospro.CompanyName_PS = HZ.Supervise.DAL.DAL_Helper.Replace(txtCompanyPS.Text.ToString().Trim()); 
            hospro.AreaID = ddlArea.SelectedAreaID;
            System.Data.DataTable dt = iEC.GetCompanyPS_ZongList_DZ(hospro, 0, 0, out t);
            if (dt.Rows.Count > 0)
            {
                AddLog(string.Format("导出配送企业列表低值数据成功!(配送企业列表)"));
                ExportFile.Instance.ExportData(dt, gvwPSLInfo, this.Page);
            }
            else
            {
                HZ.Web.WebUtil.Alert("没有数据可导出!",this);
            }

        }

        /// <summary>
        /// 分页事件 
        /// </summary>
        /// <param name="sender">事件发送源</param>
        /// <param name="e">事件参数</param>
        protected void CompanyList_PS_PageChanged(object sender, EventArgs e)
        {
            CompanyList_PS_DataBind();
        }
         
        protected string GetBtnClientId()
        { 
            return this.btnQuery.ClientID; 
        }
        /// <summary>
        /// 添加日志
        /// </summary>
        /// <param name="msg"></param>
        private void AddLog(string msg)
        {
            kj = new KeyOperationLogJG();
            kj.OperationLogSerialID = Guid.NewGuid().ToString();
            kj.Operator = CurrentAccount.GetUser().UserID;
            kj.OrgID = CurrentAccount.GetUser().Org.OrgID;
            kj.OperateTime = DateTime.Now;
            kj.OperateMessage = msg;
            iu.AddKeyOperationLog(kj);
        }
    }
}